package com.inxedu.os.edu.service.comment.impl;

import com.inxedu.os.edu.dao.CommentMapper;
import com.inxedu.os.edu.dao.EduCommentMapper;
import com.inxedu.os.edu.pojo.CommentParam;
import com.inxedu.os.edu.pojo.CommentResult;
import com.inxedu.os.edu.pojo.EduComment;
import com.inxedu.os.edu.service.comment.CommentService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;

import java.io.Serializable;
import java.util.Date;
import java.util.List;
@Service
public class CommentServiceImpl implements CommentService {

    @Autowired
    private EduCommentMapper eduCommentMapper;

    @Autowired
    private CommentMapper commentMapper;

    @Override
    public List<CommentResult> selectCommentByMessage(String email, String content, Integer type, Date beginCreateTime, Date endCreateTime) {
        CommentParam commentParam = new CommentParam(email,content,type,beginCreateTime,endCreateTime);
        commentParam.setpCommentId(0);
        return commentMapper.selectCommentByMessage(commentParam);
    }

    @Override
    public CommentResult selectCommentByCommentId(Integer commentId) {
        CommentParam commentParam = new CommentParam();
        commentParam.setCommentId(commentId);
        commentParam.setType(0);
        List<CommentResult> commentResults = commentMapper.selectCommentByMessage(commentParam);
        if (commentResults!=null&&commentResults.size()!=0){
            return  commentResults.get(0);
        }
        return null;
    }

    @Override
    public int updateCommentMessageByCommentId(EduComment eduComment) {
        return eduCommentMapper.updateByPrimaryKeySelective(eduComment);
    }

    @Override
    public int deleteCommentByCommentId(Integer commentId) {
        return eduCommentMapper.deleteByPrimaryKey(commentId);
    }

    @Override
    public List<CommentResult> selectCommentByPComentId(Integer pCommentId) {
        CommentParam commentParam = new CommentParam();
        commentParam.setpCommentId(pCommentId);
        commentParam.setType(0);
        return commentMapper.selectCommentByMessage(commentParam);
    }
}
